$(document).ajaxSend(function(e, xhr){
    let token = localStorage.getItem("user_token");
    console.log(token);
    xhr.setRequestHeader("user_token_header", token);
});

function getUrl(url){
    $.ajax({
        type: "get",
        url: url,
        success:function (result){
            if (result.code === "SUCCESS" && result.data != null){
                let userInfo = result.data;
                $(".container .left .card h3").text(userInfo.userName);
                $(".container .left .card a").attr("href",userInfo.githubUrl);
                $(".container .left .card .row #blog_count").text(userInfo.blogCount);
                if (userInfo.power === 1){
                    $(".container .left .card .row #power").text("admin");
                }else {
                    $(".container .left .card .row #power").text("normal");
                }
            }
        },error:function (error){
            if (error != null && error.status === 401){
                location.href = "blog_login.html";
            }
        }
    })
}

function logout() {
    //删除token
    if(confirm("确定注销吗?")){
        localStorage.removeItem("user_token");
        location.href = "/blog_login.html";
    }
}

function modify(){
    location.href="user_modify.html";
}

function displayUserList(){
    location.href="user_list.html";
}

